package com.nsl.my_youlai;


import com.nsl.my_youlai.controller.SysUserController;
import com.nsl.my_youlai.mystar.NslUtilFilePath;
import com.nsl.my_youlai.temp.Demos;
import com.spire.doc.Document;
import exception.TemplateErrorException;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import service.FillDocxTemplateWithExcelInformationService;

import java.io.File;
import java.io.IOException;




@Slf4j
@SpringBootTest
public class DocxDemo {

    @Autowired
    SysUserController sysUserController;

    @Test
    public void demo1() throws IOException, InvalidFormatException, TemplateErrorException {
        String classPath=sysUserController.getClass().getResource("/").getPath();
        log.info("classPath = {} ",classPath);

        //String docxTemplatePath=classPath+"docx/设计模板(Demo).docx";

        String docxTemplatePath="D:\\Java_Projects\\IntelliJ_IDEA-2022.2.3\\Gitee\\my_loulai\\target\\classes\\docx\\设计模板(Demo).docx";
//       String infoExcelPath="D:/Java_Projects/IntelliJ_IDEA-2022.2.3/Gitee/my_loulai/target/classes/docx/填充信息表格_v1 - 安阳.xlsx ";
        String infoExcelPath="D:\\Java_Projects\\IntelliJ_IDEA-2022.2.3\\Gitee\\my_loulai\\target\\classes\\docx\\填充信息表格_v1 - 安阳.xlsx ";
        String outputFilePath="D:\\Java_Projects\\Test\\"+ System.currentTimeMillis()+".docx";
        docxTemplatePath= NslUtilFilePath.getFilePathBasedOnClassPath("docx/填充信息表格_v1 - 安阳.xlsx");
        infoExcelPath= NslUtilFilePath.getFilePathBasedOnClassPath("docx/设计模板(Demo).docx");


        Document templateDocument=new Document(docxTemplatePath);
        FillDocxTemplateWithExcelInformationService convertService=new FillDocxTemplateWithExcelInformationService(templateDocument,infoExcelPath,outputFilePath);
        convertService.run();
        // currentDocument.dispose();
        templateDocument.dispose();
    }



    @Test
    public void testDemo1(){
        String fileString1="d:/1a.txt";
        File file1=new File(fileString1);
        System.out.println("file1.exists() = "+file1.exists());

        String fileString2="d:\\1a.txt";
        File file2=new File(fileString2);
        System.out.println("file2.exists() = "+file2.exists());

        String classPath=SysUserController.class.getResource("/").getPath();
        System.out.println("classPath = "+classPath);

        String projectPath=System.getProperty("user.dir");
        System.out.println("projectPath = "+projectPath);

        System.out.println(File.separator);



        String classpath = ClassLoader.getSystemResource(".").getPath();
        System.out.println(classpath);


        String[] args={"abc","def"};
        Demos.main(args);

        System.out.println(NslUtilFilePath.getClassPath());

        NslUtilFilePath.getFilePathBasedOnClassPath("");

        String str1="123";
        System.out.println(str1);
        fn1(str1);
        System.out.println(str1);
    }

    public void fn1(String str){
        str="abc";
        System.out.println(str);
    }

    @Test
    public void fn2(){
        String[] arrays={"abc","123"};

        System.out.println(String.join(File.separator,arrays));
    }
}
